<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>点聚合</title>
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="http://cdn.bootcss.com/leaflet/1.0.3/leaflet.css">
    <link rel="stylesheet" href="http://cdn.bootcss.com/leaflet.markercluster/1.0.3/MarkerCluster.Default.css"/>
    <link rel="stylesheet" href="http://cdn.bootcss.com/leaflet.markercluster/1.0.3/MarkerCluster.css"/>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="margin:0 auto;width: 100%;height: 100%;border: 1px solid #dddddd"></div>

<script type="text/javascript" src="http://cdn.bootcss.com/leaflet/1.0.3/leaflet.js"></script>
<script type="text/javascript" src="http://cdn.bootcss.com/leaflet.markercluster/1.0.3/leaflet.markercluster.js"></script>
<script type="text/javascript" src="../../dist/iclient9-leaflet.js"></script>
<script type="text/javascript">
    var map, resultLayer, getFeatureBySQLParams,
            dataUrl = "http://support.supermap.com.cn:8090/iserver/services/data-DynamicData/rest/data",
            url = "http://support.supermap.com.cn:8090/iserver/services/map-china400/rest/maps/China";
    map = L.map('map', {
        preferCanvas: true,
        center: [32, 104],
        maxZoom: 18,
        zoom: 4
    });
    L.supermap.tiledMapLayer(url).addTo(map);
    resultLayer = L.markerClusterGroup({
        spiderfyOnMaxZoom: false,
        showCoverageOnHover: false,
        zoomToBoundsOnClick: false
    });
    getFeatureBySQLParams = new SuperMap.GetFeaturesBySQLParameters({
        queryParameter: new SuperMap.FilterParameter({
            name: "Train@DynamicData",
            attributeFilter: "SmID>100 and SmID < 800"
        }),
        datasetNames: ["DynamicData:Train"]
    });
    loadMarkerCluster();

    function loadMarkerCluster() {
        L.supermap
                .featureService(dataUrl)
                .getFeaturesBySQL(getFeatureBySQLParams, function (serviceResult) {
                    createLayers(serviceResult.result.features);
                });
    }
    function createLayers(result) {
        if (!result || !result.features || result.features.length < 1) {
            return;
        }
        result.features.map(function (feature) {
            var latLng = L.CRS.EPSG3857.unproject(L.point(feature.geometry.coordinates));
            resultLayer.addLayer(L.marker(latLng));
        });
        resultLayer.addTo(map);
    }
</script>
</body>
</html>